#define  _CRT_SECURE_NO_WARNINGS 1

#include "string.h"

void test_string1()
{
	zzh::string s1;
	zzh::string s2("hello world");
	cout << s1.c_str() << endl;
	cout << s2.c_str() << endl;

	for (size_t i = 0; i < s2.size(); i++)
	{
		s2[i] += 2;
	}

	cout << s2.c_str() << endl;

	for (auto e : s2)
	{
		cout << e << " ";
	}
	cout << endl;

	zzh::string::iterator it = s2.begin();
	while (it != s2.end())
	{
		//*it += 2;
		cout << *it << " ";
		++it;
	}
	cout << endl;
}

void test_string2()
{
	zzh::string s1("hello world");
	s1 += 'x';
	s1 += '#';
	cout << s1.c_str() << endl;

	s1 += "hello bit";
	cout << s1.c_str() << endl;

	s1.insert(5, '$');
	cout << s1.c_str() << endl;

	s1.insert(0, '$');
	cout << s1.c_str() << endl;

	zzh::string s2("hello world");
	cout << s2.c_str() << endl;

	s2.insert(5, "$$$");
	cout << s2.c_str() << endl;

	s2.insert(0, "$$$&&&&&&&&&&&&&&&&&&&&&&&&&&&&&");
	cout << s2.c_str() << endl;
}

void test_string3()
{
	zzh::string s1("hello world");
	s1.erase(6, 100);
	cout << s1.c_str() << endl;

	zzh::string s2("hello world");
	s2.erase(6);
	cout << s2.c_str() << endl;

	zzh::string s3("hello world");
	s3.erase(6, 3);
	cout << s3.c_str() << endl;
}

void test_string4()
{
	zzh::string s("test.cpp.zip");
	size_t pos = s.find('.');
	zzh::string suffix = s.substr(pos);
	cout << suffix.c_str() << endl;

	zzh::string copy(s);
	cout << copy.c_str() << endl;

	s = suffix;
	cout << suffix.c_str() << endl;
	cout << s.c_str() << endl;

	s = s;
	cout << s.c_str() << endl;
}

void test_string5()
{
	zzh::string s1("hello world");
	zzh::string s2("hello world");

	cout << (s1 < s2) << endl;
	cout << (s1 == s2) << endl;
	cout << ("hello world" < s2) << endl;
	cout << (s1 == "hello world") << endl;
	//cout << ("hello world" == "hello world") << endl;

	cout << s1 << s2 << endl;

	zzh::string s0;
	cin >> s0;
	cout << s0 << endl;
}

void test_string6()
{
	zzh::string s1("hello world");
	zzh::string s2 = s1;

	cout << s1 << endl;
	cout << s2 << endl;

	zzh::string s3("xxxxxxxxxxxxxx");
	s1 = s3;

	cout << s1 << endl;
	cout << s3 << endl;
}

int main()
{
	test_string6();

	return 0;
}